﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using IImage = Microsoft.Maui.Graphics.IImage;
using Microsoft.Maui.Graphics;
using Plugin.Maui.Audio;



#if IOS || ANDROID || MACCATALYST
using Microsoft.Maui.Graphics.Platform;
#elif WINDOWS
using Microsoft.Maui.Graphics.Win2D;
#endif
namespace mdgame.Core.Scene_3
{
    public class GameObj3
    {
        public IAudioPlayer audioPlayer
        {
            set; get;
        }
        public float x
        {
            get; set;
        }
        public float y
        {
            get; set;
        }

        public IImage bitmap;
        public void Create(string url)
        {
            Assembly assembly = GetType().GetTypeInfo().Assembly;
            using (Stream stream = assembly.GetManifestResourceStream(url))
            {
#if IOS || ANDROID || MACCATALYST
                // PlatformImage isn't currently supported on Windows.
                bitmap = PlatformImage.FromStream(stream);
#elif WINDOWS
                bitmap = new W2DImageLoadingService().FromStream(stream);
#endif
            }
        }

        public void Draw(ICanvas args)
        {
            args.DrawImage(bitmap, x, y, bitmap.Width, bitmap.Height);
        }
        public async void CreateMusic(IAudioManager audioManager, string url)
        {
            audioPlayer = audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(url));
        }
    }
}
